<template>
  <el-container class="box">
    <el-aside width="300px">
      <div class="logo">
        <img src="@/assets/img/shop.png" />
        <span>商城管理系统</span>
      </div>
      <el-menu
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        :router="true"
        :default-active="$route.path"
      >
        <el-submenu v-for="v in menus" :key="v.id" :index="v.id + ''">
          <template #title>
            <i class="el-icon-s-home"></i>
            <span>{{ v.authName }}</span>
          </template>
          <el-menu-item
            v-for="vc in v.children"
            :key="vc.id"
            :index="'/home/' + vc.path"
          >
            <template #title>
              <i class="el-icon-s-home"></i>
              <span>{{ vc.authName }}</span>
            </template>
          </el-menu-item>
          <!-- <RouterLink
            to="/home/hello"
            :index="'/home/' + v.path"
            tag="el-menu-item"
            ><i class="el-icon-menu"></i> <span>{{ v.children[0].authName }}</span></RouterLink> -->
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div>xx</div>
        <div>
          <img class="headImg" src="../assets/img/user.jpg" alt="" />
          <span>admin</span>
          <el-dropdown>
            <i
              class="el-icon-arrow-down el-icon--right"
              style="margin-right: 15px"
            ></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <RouterView></RouterView>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
//token本质上
export default {
  data() {
    return {
      menus: [],
    };
  },
  methods: {
    async initLeftMenu() {
      try {
        let menus = await this.$api.getLeftMenu();
        // console.log(menus);
        if (menus == "error") return;
        this.menus = menus;
      } catch (error) {
        console.log("HomeView-initLeftMenu-error:", error);
      }
    },
  },
  created() {
    this.initLeftMenu();
  },
};
</script>

<style lang="less" scoped>
.box {
  background-color: @subbc;
  height: 100%;
  .logo {
    @h: 60px;
    height: @h;
    border-bottom: 2px solid #aaa;
    box-sizing: border-box;
    img {
      height: (@h - 2);
      width: (@h - 2);
      padding: (@h / 10);
      box-sizing: border-box;
      vertical-align: middle;
      padding-left: 10px;
    }
    span {
      vertical-align: middle;
      font-size: 24px;
      padding-left: 10px;
    }
  }
}
.el-aside {
  background-color: #545c64;
  box-shadow: 0px 0px 12px #999;
  // color: white;
}
.el-header {
  background-color: #ffffff;
  box-shadow: 0 0 12px #444;
  display: flex;
  justify-content: space-between;
  align-items: center;
  div:last-of-type {
    display: flex;
    align-items: center;
  }
  .headImg {
    width: 42px;
    border-radius: 50%;
    margin-right: 5px;
  }
}

.el-menu {
  border: unset;
}

</style>